<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\Common\Service\Affiliate\JdService;
use App\CustHub\Service\AffiliateAccountService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Mine\MineController;
use function Hyperf\Collection\value;

#[Controller('callback')]
class CallbackController extends MineController
{

    #[Inject]
    protected AffiliateAccountService  $affiliateAccountService;


    /**
     * 淘宝授权回调
     * @param int $uid
     * @param int $main_uid
     * @param string $suc_jump
     * @param int $type
     * @return \Psr\Http\Message\ResponseInterface
     */
    #[RequestMapping('loginCallback/{uid}/{main_uid}/{suc_jump}/{type}')]
    public function loginCallback(int $uid,int $main_uid,string $suc_jump,int $type): \Psr\Http\Message\ResponseInterface
    {
        $data = array_merge(compact('uid','main_uid','suc_jump','type'),$this->request->all());
        $result = $this->affiliateAccountService->tbOauthCallback($data);
        if($result !== false){
            return $this->response->html($result);
        }else{
            return $this->response->raw('授权失败');
        }
    }

    /**
     * 京东授权回调
     * @return \Psr\Http\Message\ResponseInterface
     */
    #[RequestMapping('jdLoginCallback/{uid}/{main_uid}/{suc_jump}/{type}')]
    public function jdLoginCallback(int $uid,int $main_uid,string $suc_jump,int $type): \Psr\Http\Message\ResponseInterface
    {
        $data = array_merge(compact('uid','main_uid','suc_jump','type'),$this->request->all());

        $result = $this->affiliateAccountService->jdOauthCallback($data);
        if($result !== false){
            return $this->response->html($result);
        }else{
            return $this->response->raw('授权失败');
        }
    }

    /**
     * 拼多多授权回调
     * @param int $uid
     * @param int $main_uid
     * @param string $suc_jump
     * @param int $type
     * @return \Psr\Http\Message\ResponseInterface
     */
    #[RequestMapping('pddLoginCallback/{uid}/{main_uid}/{suc_jump}/{type}')]
    public function pddLoginCallback(int $uid,int $main_uid,string $suc_jump,int $type): \Psr\Http\Message\ResponseInterface
    {
        $data = array_merge(compact('uid','main_uid','suc_jump','type'),$this->request->all());
        $result = $this->affiliateAccountService->pddOauthCallback($data);
        if($result !== false){
            return $this->response->html($result);
        }else{
            return $this->response->raw('授权失败');
        }
    }

    /**
     * 拼多多授权回调
     * @param int $uid
     * @param int $main_uid
     * @param string $suc_jump
     * @param int $type
     * @return \Psr\Http\Message\ResponseInterface
     */
    #[RequestMapping('wphLoginCallback/{uid}/{main_uid}/{suc_jump}/{type}')]
    public function wphLoginCallback(int $uid,int $main_uid,string $suc_jump,int $type): \Psr\Http\Message\ResponseInterface
    {
        $data = array_merge(compact('uid','main_uid','suc_jump','type'),$this->request->all());
        $result = $this->affiliateAccountService->wphOauthCallback($data);
        if($result !== false){
            return $this->response->html($result);
        }else{
            return $this->response->raw('授权失败');
        }
    }
}